OpenBuildings GenerativeComponents Help

SortIndices

Returns a list of (integer) indices that indicate a sorted sequence of the given list.

int[] SortIndices(object[] list,bool function(object x,
object y, ...) putBefore, ...)

The given function specifies the sort criteria. Given any two members, x and y, that function returns true if x should be put before y in the sorted sequence.

How to use it

a) One line format:

int[] sortedIndices= SortIndices(numbers, function(x, y)
{ return x < y; });

b) Multi-line format:

function putBefore(x, y)
{
	return x < y;
}
int [] sortedIndices = Sort(numbers, putBefore);

The sortIndices function goes through pairs of values at a time making comparisons according to the supplied sort criteria. The boolean putBefore function determines whether a number be put before another in the list. If this function returns true, it means that, when the list is sorted, x should be placed before y. In contrast to the sort function, rather than returning the list of features, the sortIndices function returns the sorted list of indices.

Example

A) Sort Indices of a Point sequentially by X, Y. If this function returns true, it means that, when the list is sorted, x should be placed before y. The extra 'or' statement serves as secondary sort function.

bool function sortByXY(pt1, pt2)
{
	return pt1.XZTranslation < pt2.XTranslation
	|| (pt1.X == pt2.XTranslation && pt1.YTranslation
<  pt2.YTranslation);
}
int sortedIndices = SortIndices(scatterPoint, sortByXY);